<!-- changepassword -->
<template>
  <div class="changepassword">
    <el-form
      :model="ruleForm"
      status-icon
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
      :label-position="labelPosition"
    >
      <el-form-item label="原密码" prop="age">
        <el-input v-model.number="ruleForm.age"></el-input>
      </el-form-item>
      <el-form-item label="新密码" prop="pass">
        <el-input
          type="password"
          v-model="ruleForm.pass"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <el-form-item label="重复密码" prop="checkPass">
        <el-input
          type="password"
          v-model="ruleForm.checkPass"
          autocomplete="off"
        ></el-input>
      </el-form-item>
    </el-form>
    <div class="form_btn">
      <div class="quxiao">取消</div>
      <div class="tijiao">提交</div>
    </div>
  </div>
</template>

<script>
/**
 * @name 用户修改密码
 */

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    var checkAge = (rule, value, callback) => {
      if (!value) return callback(new Error("原密码不能为空"));
      setTimeout(() => {
        if (!Number.isInteger(value)) callback(new Error("请输入数字值"));
        else {
          if (value < 18) callback(new Error("必须年满18岁"));
          else callback();
        }
      }, 1000);
    };
    var validatePass = (rule, value, callback) => {
      if (value === "") callback(new Error("请输入密码"));
      else {
        if (this.ruleForm.checkPass !== "")
          this.$refs.ruleForm.validateField("checkPass");
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === "") callback(new Error("请再次输入密码"));
      else if (value !== this.ruleForm.pass)
        callback(new Error("两次输入密码不一致!"));
      else callback();
    };
    return {
      labelPosition: "top",
      ruleForm: {
        pass: "",
        checkPass: "",
        age: "",
      },
      rules: {
        pass: [{ validator: validatePass, trigger: "blur" }],
        checkPass: [{ validator: validatePass2, trigger: "blur" }],
        age: [{ validator: checkAge, trigger: "blur" }],
      },
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) alert("submit!");
        else return false;
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
  beforeCreate() {}, //生命周期 - 创建之前
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  beforeMount() {}, //生命周期 - 挂载之前
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang="less" >
@import "../../assets/styles/frame.less";
.changepassword {
  margin: auto;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  width: 400px;
  height: 400px;
  padding: 42px 60px 48px;
  background: #ffffff;
  box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.13);
  border-radius: 14px;
  font-size: 14px;
  z-index: 9999;
  .form_btn {
    width: 100%;
    height: 40px;
    font-weight: 600;
    .divAJS();
    margin-top: 60px;
    .quxiao {
      width: 120px;
      height: 40px;
      background: #ffffff;
      border: 1px solid #cacaca;
      border-radius: 2px;
      .cen();
    }
    .tijiao {
      width: 120px;
      height: 40px;
      background: #3f3f3f;
      border-radius: 2px;
      color: #fff;
      .cen();
    }
  }
}
</style>